package TankWar;

import java.awt.*;

public class Tank {
    private int x;
    private int y;
    private Direction direction;
    private int speed;
    private int life;

    public Tank(int x, int y, Direction direction, int speed, int life) {
        this.x = x;
        this.y = y;
        this.direction = direction;
        this.speed = speed;
        this.life = life;
    }

    public void move() {
        // 根据方向和速度移动坦克的位置
        switch (direction) {
            case UP:
                y -= speed;
                break;
            case DOWN:
                y += speed;
                break;
            case LEFT:
                x -= speed;
                break;
            case RIGHT:
                x += speed;
                break;
        }
    }

    public void shoot() {
        // 创建子弹并发射
        Bullet bullet = new Bullet(x, y, direction);
        // 将子弹添加到游戏的子弹列表中
    }

    public void draw(Graphics g) {
        // 根据坦克的位置和方向绘制坦克图形
        // 可以使用 drawImage 方法绘制坦克的图片
        g.drawRect(x, y, 40, 40);
    }

    // 其他方法和属性的 getter 和 setter
    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    public Direction getDirection() {
        return direction;
    }

    public int getLife() {
        return life;
    }

    public void setX(int x) {
        this.x = x;
    }

    public void setY(int y) {
        this.y = y;
    }

    public void setDirection(Direction direction) {
        this.direction = direction;
    }

    public void setSpeed(int speed) {
        this.speed = speed;
    }

    public void setLife(int life) {
        this.life = life;
    }

    public enum Direction {
        UP, DOWN, LEFT, RIGHT, STOP
    }
}
